package com.mid;

/**
 * Created by Lxk on 2020/2/1.
 */
public class Solution63 {

    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int col = obstacleGrid[0].length, row = obstacleGrid.length;
        int[][] dp = new int[row][col];
        boolean obstacleFlag = false;
        for (int i = 0; i < col; i++) {
            if (obstacleGrid[0][i] == 0) {
                dp[0][i] = 1;
            } else {
                break;
            }
        }
        for (int i = 0; i < row; i++) {
            if (obstacleGrid[i][0] == 0) {
                dp[i][0] = 1;
            } else {
                break;
            }
        }
        for (int i = 1; i < row; i++) {
            for (int k = 1; k < col; k++) {
                if (obstacleGrid[i][k] == 1) {
                    dp[i][k] = 0;
                } else {
                    dp[i][k] = dp[i - 1][k] + dp[i][k - 1];
                }
            }
        }
        return dp[row - 1][col - 1];
    }

    public static void main(String[] args) {
        int[][] obstacleGrid = {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}};
        Solution63 solution63 = new Solution63();
        System.out.println(solution63.uniquePathsWithObstacles(obstacleGrid));
    }

}
